﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class Clients_Control_download : System.Web.UI.UserControl
{

    private String strLiDiv = "<li> <a href='"+Constant.ROOT_PATH+"$link'>$text</a></li>";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            LoadDataDownLoad();
            String strPage = "";
            try
            {
                strPage = Request.Params["Pro"].ToString().Trim();
            }
            catch
            {

            }
            lblContentTitle.Text = Constant.ContentTitle(strPage);
        }
    }

    private void LoadDataDownLoad() {
  
            WebData data = new WebData();
            int groupID = -1;
            try {
                groupID = int.Parse(Request.Params["id"].ToString());
            }
            catch {
                groupID = -1;
            }
            List<DataLibrary.tbl_Download> list ;//= data.tbl_Downloads.GetListCache("download",Constant.time).FindAll(p=>p.IsActive==1);
            if (groupID != -1) {
                list = data.tbl_Downloads.GetListCache("download", Constant.time).FindAll(p => p.IsActive == 1 && p.GroupID==groupID);
            }
            else {
                list = data.tbl_Downloads.GetListCache("download", Constant.time).FindAll(p => p.IsActive == 1);
            }
            this.grdDownload.DataSource = list.Skip(0).Take(6);
            this.grdDownload.DataBind();
            String url = "";
            if (list.Count> 6) {
                int l=list.Count;
                
                for (int i = 6; i < l; i++) {
                    try
                    {
                        if (!string.IsNullOrEmpty(list[i].Title.ToString()))
                        {
                            String str = String.Format("{0}/{1}/{2}",Constant.StrDownload, list[i].Id.ToString(),
                                Constant.ChangeString(list[i].Title.ToString()));
                            url = url + strLiDiv.Replace("$text", list[i].Title.ToString()).Replace("$link", str);
                        }
                    }
                    catch { }
                }
                
                ltlDownLoad.Text = url;
        }
            if (String.IsNullOrEmpty(url))
            {
                lblOther.Visible = false;
            }
            else
            {
                lblOther.Visible = true;
            }
    }
}